interface Tree {
  children: []
  department_name: ''
}
interface arr { }
export const usePositionName = (obj: Tree[]) => {
  let childrenArr: arr[] = []
  let _setPositionName = (obj: Tree[]) => {
    for (let i = 0; i < obj.length; i++) {
      if (
        obj[i].children &&
        obj[i].children.length &&
        obj[i].children.length !== 0
      ) {
        childrenArr.push(obj[i].children)
        _setPositionName(obj[i].children)
      }
    }
    return childrenArr
  }
  _setPositionName(obj)
  if (childrenArr && childrenArr.length) {
    let newchildrenArr: arr[] = []
    const _setChildrenName = (obj: any) => {
      for (let i = 0; i < obj.length; i++) {
        if (obj[i] && obj[i].length !== 0) {
          newchildrenArr.push(obj[i])
          _setChildrenName(obj[i])
        }
      }
      return newchildrenArr
    }
    _setChildrenName(childrenArr)

    let filiterChildrenArr: arr[] = []
    newchildrenArr.map((item) => {
      if (!Array.isArray(item)) {
        filiterChildrenArr.push(item)
      }
    })
    let arr = JSON.parse(JSON.stringify(filiterChildrenArr))
    for (let i = 0; i <= arr.length; i++) {
      for (let j = i + 1; j < arr.length; j++) {
        if (arr[i].department_name === arr[j].department_name) {
          arr.splice(j, 1)
        }
      }
    }
    return arr
  }
}